{extend name="public/base" /}

{block name="style"}
<link rel="stylesheet" href="__STATIC__/css/floating-labels.css">
<style>
    .form-control {
        height: inherit;
    }
</style>
{/block}

{block name="content"}
<form class="form-signin" method="post" id="login">
    {:token()}
    <div class="text-center mb-4 mt-5">
        <h1 class="h3 mb-3 font-weight-normal">会员登录</h1>
        <p class="text-muted">没有账号 <a href="{:url('User/register')}">注册</a></p>
    </div>

    <div class="form-label-group">
        <input type="email" name="email" id="inputEmail" class="form-control" placeholder="输入邮箱" required autofocus>
        <label for="inputEmail">输入邮箱</label>
    </div>

    <div class="form-label-group">
        <input type="password" name="password" id="inputPassword" class="form-control" placeholder="输入密码" required>
        <label for="inputPassword">输入密码</label>
    </div>


    <button class="btn btn-lg btn-primary btn-block mt-3 mt-md-auto" type="button" id="register">登录</button>
    <div class="mt-2">
        <a href="" class="text-muted">忘记密码</a>
    </div>

</form>
{/block}


{block name="script"}
<script>
    toastr.options = {
        "closeButton": true,
        "positionClass": "toast-top-center",
        "timeOut": "1500"
    };

    $('#register').on('click',function () {
        $.ajax({
            type: 'post',
            url: "{:url('User/loginDo')}",
            data: $('#login').serialize(),
            dataType: 'json',
            success: function (data) {
                switch (data.status) {
                    case 1:
                        toastr.success(data.message);
                        setTimeout(function () {
                            window.location.href = "{:url('User/index')}";
                        },1500);
                        break;
                    case 0:
                    case -1:
                    case -2:
                        $('input[name="__token__"]').val(data.token);
                        toastr.warning(data.message);
                        break;
                }
            }
        })
    })
</script>
{/block}